import 'package:flutter/material.dart';

///todo:自定义文本按钮
class TextButton extends StatefulWidget {
  double fontSize; //按钮文本大小
  Color bgColor; //按钮背景颜色
  Color txtColor; //按钮文本颜色
  double width; //按钮宽
  double height; //按钮高
  double radius; //按钮统一圆角
  double radiusTopLeft; //按钮左上圆角
  double radiusTopRight; //按钮右上角
  double radiusBottomLeft; //按钮左下
  double radiusBottomRight; //按钮右下
  String text; //按钮文本
  Color borderColor; //按钮边框颜色
  VoidCallback onPressed; //按钮点击事件
  bool isShow = true; //判断设置的圆角（true为设置四个同样的圆角  false为设置四个不同的圆角）
  TextButton(
      {Key key,
        this.text: "按钮",
        this.bgColor,
        this.txtColor,
        this.fontSize,
        this.radius: 5,
        this.radiusBottomLeft: 5,
        this.radiusBottomRight: 5,
        this.radiusTopLeft: 5,
        this.radiusTopRight: 5,
        this.height: 44,
        this.width: 351,
        this.onPressed,
        this.borderColor: Colors.blue,
        this.isShow: true})
      : super(key: key);

  @override
  _TextButtonState createState() => _TextButtonState();
}

class _TextButtonState extends State<TextButton> {
  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: widget.onPressed,
      child: ConstrainedBox(
        constraints: BoxConstraints(
          maxWidth: MediaQuery.of(context).size.width,
          minWidth: 0.0,
          minHeight: 0.0,
          maxHeight: MediaQuery.of(context).size.height,
        ),
        child: Container(
          width: widget.width,
          height: widget.height,
//        padding: EdgeInsets.only(left: 10,right: 10,top: 0,bottom: 0),
          decoration: BoxDecoration(
            color: widget.bgColor ?? Colors.blueAccent,
            borderRadius: widget.isShow
                ? new BorderRadius.only(
                topLeft: new Radius.circular(widget.radius),
                topRight: new Radius.circular(widget.radius),
                bottomLeft: new Radius.circular(widget.radius),
                bottomRight: new Radius.circular(widget.radius))
                : new BorderRadius.only(
                topLeft: new Radius.circular(widget.radiusTopLeft),
                topRight: new Radius.circular(widget.radiusTopRight),
                bottomLeft: new Radius.circular(widget.radiusBottomLeft),
                bottomRight: new Radius.circular(widget.radiusBottomRight)),
            border: Border.all(color: widget.borderColor ?? Colors.blueAccent),
          ),
          child: Align(
            child: Text(widget.text,
                style: TextStyle(
                    fontSize: widget.fontSize,
                    color: widget.txtColor ?? Colors.white)),
          ),
        ),
      ),
    );
  }
}